package com.sctvcloud.zhaohua_sd.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;

import com.gridsum.tracker.GridsumWebDissector;
import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.zhaohua_sd.R;
import com.sctvcloud.zhaohua_sd.base.BaseActivity;
import com.sctvcloud.zhaohua_sd.beans.FSubscribe;
import com.sctvcloud.zhaohua_sd.ui.activities.LivingActivity;
import com.sctvcloud.zhaohua_sd.ui.utils.GlideUtil;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/6/22 0022.
 */

public class MySubscribeHolder extends BaseRecylerHolder<FSubscribe> {

    @BindView(R.id.item_live_item_img)
    protected CustomEXImageView subscribe_img;
    @BindView(R.id.item_mysubscribe_title)
    protected CustomFontTextView subscribe_title;
    @BindView(R.id.item_item_mysubscribe_status)
    protected CustomFontTextView subscribe_status;
    @BindView(R.id.item_item_mysubscribe_time)
    protected CustomFontTextView subscribe_time;
    private OnItemInternalClick onItemInternalClick;
    private FSubscribe subscribe;
    protected ArrayList<Pair<String, String>> pairs;

    public MySubscribeHolder(Context context, View itemView) {
        super(context, itemView);
        this.pairs = new ArrayList<>();
        //itemView.setOnClickListener(this);
    }

    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
    }

    @Override
    public void setData(FSubscribe subscribe) {
        this.subscribe = subscribe;
        if (!TextUtils.isEmpty(subscribe.getLiveImage())) {
            GlideUtil.loadImgLarge169Def(context, subscribe.getLiveImage(), subscribe_img);
        }
        subscribe_title.setText(!TextUtils.isEmpty(subscribe.getLiveTitle()) ? subscribe.getLiveTitle() : "");
        subscribe_time.setText(!TextUtils.isEmpty(subscribe.getLiveTime()) ? DateUtils.formatDate(DateUtils.getDataDate(subscribe), "MM-dd HH:mm") : "");
        subscribe_status.setBackgroundResource(subscribe.isSubscribe() ? R.drawable.bg_subscribe_bt_gray : R.drawable.bg_subscribe_bt_red);
        subscribe_status.setText(subscribe.isSubscribe() ? context.getString(R.string.already_subscribe) : context.getString(R.string.subscribe));

    }

//    @Override
//    public void onClick(View v) {
//        Intent intent = new Intent(context, LivingActivity.class);
//        intent.putExtra(BaseActivity.EX_URL, subscribe.getLiveUrl());
//        context.startActivity(intent);
//    }

    @OnClick(value = {R.id.item_item_mysubscribe_status, R.id.item_live_item_img})
    public void subscribeClick(View view) {
        if (view.getId() == R.id.item_item_mysubscribe_status) {
            if (onItemInternalClick != null) {
                itemView.setTag(R.id.adapter_item_data_key, subscribe);
                onItemInternalClick.onItemInternalClick(itemView, view, getAdapterPosition());
            }
        } else if (view.getId() == R.id.item_live_item_img) {
            Intent intent = new Intent(context, LivingActivity.class);
//		if (liveItem != null && liveItem.isLiving()) {
            intent.putExtra(BaseActivity.EX_URL, subscribe.getLiveUrl());
            intent.putExtra(BaseActivity.EX_DATA, subscribe.getLiveImage());

            intent.putExtra(LivingActivity.ADVANCE_TYPE, true);
            intent.putExtra(LivingActivity.ADVANCE_TITLE, subscribe.getLiveTitle());
            intent.putExtra(LivingActivity.ADVANCE_IMAGE_URL, subscribe.getLiveImage());
            intent.putExtra(LivingActivity.ADVANCE_START_TIME, subscribe.getLiveTime());
            pairs.add(new Pair<String, String>("位置", "直播预约"));
            HashMap<String, String> map = new HashMap<>();
            for (Pair<String, String> pair : pairs) {
                map.put(pair.first, pair.second);
            }
            intent.putExtra("TAG", map);
            context.startActivity(intent);
        }
    }

    public OnItemInternalClick getOnItemInternalClick() {
        return onItemInternalClick;
    }

    public MySubscribeHolder setOnItemInternalClick(OnItemInternalClick onItemInternalClick) {
        this.onItemInternalClick = onItemInternalClick;
        return this;
    }
}
